<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style>
        body {
            background: #f8f8f8;
        }

        .search {
            margin-right: 0.5rem;
            background: #fd5454;
            font-size: 0.6rem;
            padding: 0.2rem 0.5rem;
            border-radius: 0.2rem;
            color: #ffffff;
        }

        .total {
            text-align: center;
            color: #505050;
            margin: 1rem;
        }

        .aui-searchbar-input input {
            width: 90%;
        }
    </style>
</head>

<body>
    <div class="vue">
        <div class="loading" v-if="loading"></div>
        <div class="aui-searchbar" id="search" style="margin-bottom:0.5rem;border-radius:0.3rem">
            <div class="aui-searchbar-input aui-border-radius">
                <i class="aui-iconfont aui-icon-search"></i>
                <input type="search" placeholder="姓名、手机号" id="search-input" v-model="keyword">
            </div>
            <span class="search" @click="doSearch">搜索</span>
        </div>
        <div class="total">共 {{total}} 位会员</div>
        <div class="aui-content">
            <ul class="aui-list aui-media-list">
                <li class="aui-list-item aui-list-item-middle" v-for="(item,index) in list">
                    <div class="aui-media-list-item-inner">
                        <div class="aui-list-item-media" style="width: 3rem;">
                            <img :src="item.user_headimg" class="aui-img-round aui-list-img-sm">
                        </div>
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-text">
                                <div class="aui-list-item-title aui-font-size-14">{{item.nick_name}}</div>
                            </div>
                            <div class="aui-list-item-text">{{item.user_name}}</div>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
    </div>
    <script type="text/javascript" src="../script/vue.js"></script>
    <script type="text/javascript" src="../script/base64.js"></script>
    <script type="text/javascript" src="../script/app.js"></script>
    <script type="text/javascript">
        apiready = function() {
            var user = app.getUser();

            api.setRefreshHeaderInfo({
                loadingImg: 'widget://image/refresh.png',
                bgColor: '#f8f8f8',
                textColor: '#505050',
                textDown: '下拉刷新...',
                textUp: '松开刷新...'
            }, function(ret, err) {
                Ve.getMembers(function() {
                    Ve.list = [];
                    api.refreshHeaderLoadDone();
                })
            });

            api.addEventListener({
                name: 'scrolltobottom',
                extra: {
                    threshold: 15
                }
            }, function(ret, err) {

            });

            var Ve = new Vue({
                el: '.vue',
                data: {
                    loading: true,
                    total: 0,
                    list: [],
                    keyword: ''
                },
                methods: {
                    getMembers: function(callback) {
                        app.request.post('/myhome/business_member', {
                            business_id: user.business_id,
                            search_input: this.keyword,
                            signature: app.sign(user.business_id)
                        }, {}, function(res) {
                            // console.log(JSON.stringify(res))
                            callback && callback()
                            if (res.code == 1) {
                                Ve.total = res.count
                                for (var i in res.data) {
                                    Ve.list.push(res.data[i])
                                }
                            } else {
                                app.error(res.msg);
                            }
                            app.loadingFinish(Ve)
                        })
                    },
                    doSearch: function() {
                        this.list = []
                        this.page = 1
                        this.getMembers()
                    }
                },
                created: function() {
                    this.getMembers()
                }
            })
        }
    </script>
</body>

</html>
